package com.guigu.gcservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.commonutils.R;
import com.guigu.gcservice.entity.Gongcheng;
import com.guigu.gcservice.entity.Say;
import com.guigu.gcservice.service.SayService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-16
 */
@RestController
@RequestMapping("/gcservice/say")
@CrossOrigin
public class SayController {
    @Autowired
    private SayService sayService;
    //保存留言
    @PostMapping("say")
    public R addsay(@RequestBody Say say){
        boolean save = sayService.save(say);
        String a = say.getSaying().toString();
        System.out.println(a);
        if(save){
            return R.ok();
        }else{
            return R.error();
        }
    }
    //3,分页查询方法
    //current 当前页
    //limit   每页记录数
    @ApiOperation(value = "分页查询留言方法")
    @PostMapping("saypage/{current}/{limit}")
    public R pageListTeacher(@PathVariable long current,
                             @PathVariable long limit){
        //创建page对象
        Page<Say> page = new Page<>(current,limit);
        //调用方法实现分页
        //调用方法时候底层封装，把分页所有数据封装到pageTeacher对象里面
        sayService.page(page,null);
        long total = page.getTotal();//总记录数
        List<Say> records = page.getRecords();//数据list集合
        System.out.println(records);
        return R.ok().data("total",total).data("row",records);
    }
}

